package com.shoux.api.exception;

import com.shoux.api.tools.MsgUtils;
import com.shoux.api.web.entity.MsgEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 *
 * @author ding
 * @date 2021/5/20 13:54
 */

@ControllerAdvice
@ResponseBody
@Slf4j
public class JrfkExceptionHandler {

    @ExceptionHandler(AbstractJrfkException.class)
    public MsgEntity jrfkHandler(AbstractJrfkException e) {
        e.printStackTrace();
        return MsgUtils.getMsg(false, e.getStatus().name(), e.getMessage(), e.getErrorData());
    }

    @ExceptionHandler(Exception.class)
    public MsgEntity exception(Exception e) {
        e.printStackTrace();
        return MsgUtils.getMsg(false, e.getMessage());
    }
}
